package com.itzol.controller;

import com.itzol.entity.UserLoginParam;
import com.itzol.entity.Users;
import com.itzol.service.UsersService;
import com.itzol.uitls.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

@RestController
public class LoginController {
    @Autowired
    private UsersService usersService;
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginParam userLoginParam){
        return usersService.login(userLoginParam.getUsername(),userLoginParam.getPassword());
    }

    @GetMapping("/hello")
    public Users getUserInfo(Principal principal){
        if(null==principal){
            return null;
        }
        String username = principal.getName();
        Users users = usersService.getUserInfo(username);
        users.setPassword(null);
        return users;
    }

}
